package authenum

import (
	"yunj/pkg/yunj/core/enum"
)

// 定义常量
const (
	REQUEST_MODE_NIL             uint8 = 0
	REQUEST_MODE_INTERNAL_ROUTER uint8 = 11
	REQUEST_MODE_EXTERNAL_URL    uint8 = 22
)

// 实现EnumInerface接口
type RequestMode struct {
	enum.Enum[uint8]
}

func (e *RequestMode) AllConstAttrs() map[uint8]map[string]any {
	return map[uint8]map[string]any{
		REQUEST_MODE_NIL: {
			"desc": "无",
			"sort": 1,
		},
		REQUEST_MODE_INTERNAL_ROUTER: {
			"desc": "内部路由",
			"sort": 2,
		},
		REQUEST_MODE_EXTERNAL_URL: {
			"desc": "外部地址",
			"sort": 3,
		},
	}
}

// instanceCache 存储已经创建的实例
var requestModeInstanceCache = make(map[uint8]*RequestMode)

// 根据value获取枚举
func RequestModeByValue(value uint8) *RequestMode {
	if instance, exists := requestModeInstanceCache[value]; exists {
		return instance
	}
	e := &RequestMode{}
	enum.SetEnumInstance(&e.Enum, e, value)
	requestModeInstanceCache[value] = e
	return e
}

var RequestModeEnum *RequestMode = func() *RequestMode {
	e := &RequestMode{}
	enum.SetEnumInstance(&e.Enum, e)
	return e
}()
